package com.example.service;

import com.example.dao.NxTypeInfoDao;
import org.springframework.stereotype.Service;
import com.example.entity.NxTypeInfo;
import com.example.vo.NxTypeInfoVo;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class NxTypeInfoService {

    @Resource
    private NxTypeInfoDao nxTypeInfoDao;

    public NxTypeInfo add(NxTypeInfo nxTypeInfo) {
        nxTypeInfoDao.insertSelective(nxTypeInfo);
        return nxTypeInfo;
    }

    public void delete(Long id) {
        nxTypeInfoDao.deleteByPrimaryKey(id);
    }

    public void update(NxTypeInfo nxTypeInfo) {
        nxTypeInfoDao.updateByPrimaryKeySelective(nxTypeInfo);
    }

    public NxTypeInfo findById(Long id) {
        return nxTypeInfoDao.selectByPrimaryKey(id);
    }

    public List<NxTypeInfoVo> findAll() {
        return nxTypeInfoDao.findByName("all");
    }

    public PageInfo<NxTypeInfoVo> findPage(String name, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        PageHelper.startPage(pageNum, pageSize);
        List<NxTypeInfoVo> all = findAllPage(request, name);
        return PageInfo.of(all);
    }

    public List<NxTypeInfoVo> findAllPage(HttpServletRequest request, String name) {
		return nxTypeInfoDao.findByName(name);
    }

}
